Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 2 - Geometric Shapes / Using Geometric Shapes


Editing Shape Parts

The GXSetShapeParts function is more general than the GXSetPolygonParts and GXSetPathParts functions described in the previous two sections. The GXSetShapeParts function allows you to replace a subset of the geometric points in one shape with the geometric points in the geometry of another shape.

For example, with GXSetShapeParts you could replace the last three geometric points of a polygon shape with the geometry of a line shape, or you could replace the first geometric point of a path shape with the entire geometry of a polygon shape.

The sample function in Listing 2-32 creates a path shape with one contour. Later examples in this section use this path shape to demonstrate editing shape parts.

Listing 2-32 Creating a path shape with one contour

void CreatePathShape(void)
{
   gxShape  aPathShape;

   static long twoCurveGeometry[] = {1, /* number of contours */
                                     6, /* number of points */
                                     0x48000000, /* 0100 1000 */
                                     ff(100), ff(150),  /* on */
                                     ff(50),  ff(100),  /* off */
                                     ff(100), ff(50),   /* on */
                                     ff(200), ff(50),   /* on */
                                     ff(250), ff(100),  /* off */
                                     ff(200), ff(150)}; /* on */

   aPathsShape = GXNewPaths((gxPaths *) twoCurveGeometry);
   GXSetShapeFill(aPathShape, gxOpenFrameFill);

   GXDrawShape(aPathShape);

   GXDisposeShape(aPathShape);
}
The resulting shape is shown in Figure 2-61.

Figure 2-61 A path shape with a flat top

To insert a new geometric point in this shape using the GXSetShapeParts function, you must first encapsulate the new geometric point in a point shape:

static gxPoint newTopGeometry = {ff(150), ff(20)}; 
gxShape aPointShape;
aPointShape = GXNewPoint(&newTopGeometry);
Then you call the GXSetShapeParts function:

GXSetShapeParts(aPathsShape, 4, 0, aPointShape, 
                gxBreakNeitherEdit);
Since you must create a shape to encapsulate the point geometry, you should dispose of this shape when you no longer need it:

GXDisposeShape(aPointShape);
The resulting path shape is shown in Figure 2-62.

Figure 2-62 A path shape edited to have a pointy top

You can also use the GXSetShapeParts function to insert an off-curve control point in the path shape. To do this, however, you must encapsulate the new geometric point into a path shape, because only a path shape can contain a single off-curve point.

gxShape aSingleOffCurvePoint;
static long newTopGeometry[] = {1, /* number of contours */
                                1, /* number of points */
                                0x80000000, /* 1000 ... */
                                ff(150), ff(20)}; /* off curve */


aSingleOffCurvePoint = GXNewPaths((gxPaths *) newTopGeometry);
GXSetShapeParts(aPathsShape, 4, 0, 
                aSingleOffCurvePoint, gxBreakNeitherEdit);
GXDisposeShape(aSingleOffCurvePoint);
The resulting path shape is shown in Figure 2-63.

Figure 2-63 A path shape edited to have a round top

The GXSetShapeParts function allows you to edit the geometry of any shape. For example, the sample function in Listing 2-33 creates a line shape and uses GXSetShapeParts to change the last point.

Listing 2-33 Creating a diagonal line

void CreateDiagonalLine(void)
{
   gxShape aLineShape;
   gxShape aPointShape;

   static gxLine lineGeometry = {ff(50), ff(50),
                                 ff(150), ff(150)};

   static gxPoint newLastPointGeometry = {ff(300), ff(150)};
   aLineShape = GXNewLine(&lineGeometry);
   GXSetShapeFill(aLineShape, gxOpenFrameFill);

   aPointShape = GXNewPoint(&newLastPointGeometry);
   GXSetShapeParts(aLineShape, 2, 1, aPointShape, 
                   gxBreakNeitherEdit);
   GXDisposeShape(aPointShape);
   GXDrawShape(aLineShape);
   GXDisposeShape(aLineShape);
}
The original line is shown in Figure 2-64.

Figure 2-64 A diagonal line

The line shape with the replaced last point is shown in Figure 2-65.

Figure 2-65 An edited line

For more information about editing shape parts and the GXSetShapeParts function, see the function description on page 2-154.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help